import Vue from 'vue'
import App from './App'

// vuex
import store from './store'

// 引入全局uView
import uView from '@/uni_modules/uview-ui'

import mixin from './common/mixin'

import * as RongIMLib from '@rongcloud/imlib-v4'
const im = RongIMLib.init({
	appkey: 'm7ua80gbmzhjm'
}); // c9kqb3rdcqegj
// 添加事件监听
im.watch({
	// 监听会话列表变更事件
	conversation(event) {
		// 发生变更的会话列表
		const updatedConversationList = event.updatedConversationList;
	},
	// 监听消息通知
	message(event) {
		// 新接收到的消息内容
		const message = event.message;
		uni.showTabBarRedDot({
			index: 3
		});
	},
	// 监听 IM 连接状态变化
	status(event) {
		console.log('connection status:', event.status);
	},
	// 监听聊天室 KV 数据变更
	chatroom(event) {
		/**
		 * 聊天室 KV 存储数据更新
		 * @example
		 * [
		 *  {
		 *    "key": "name",
		 *    "value": "我是小融融",
		 *    "timestamp": 1597591258338, 
		 *    "chatroomId": "z002", 
		 *    "type": 1 // 1: 更新（ 含:修改和新增 ）、2: 删除
		 *  },
		 * ]
		 */
		const updatedEntries = event.updatedEntries
	},
	expansion(event) {
		/**
		 * 更新的消息拓展数据
		 * @example {
		 *    expansion: { key: 'value' },      // 设置或更新的扩展值
		 *    messageUId: 'URIT-URIT-ODMF-DURR' // 设置或更新扩展的消息 uid
		 * }
		 */
		const updatedExpansion = event.updatedExpansion;
		/**
		 * 删除的消息拓展数据
		 * @example {
		 *    deletedKeys: ['key1', 'key2'],    // 设置或更新的扩展值
		 *    messageUId: 'URIT-URIT-ODMF-DURR' // 设置或更新扩展的消息 uid
		 * }
		 */
		const deletedExpansion = event.deletedExpansion;
	}
});
Vue.prototype.$ry = im
Vue.prototype.$store = store

Vue.config.productionTip = false

App.mpType = 'app'
Vue.use(uView)

// #ifdef MP
// 引入uView对小程序分享的mixin封装
const mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js')
Vue.mixin(mpShare)
// #endif

Vue.mixin(mixin)

const app = new Vue({
	store,
	...App
})

// 引入请求封装
require('./util/request/index')(app)
import * as api from './common/api.js'
Vue.prototype.$api = api

app.$mount()
